package com.dong.keyboardlayoutdemo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.view.View
import android.widget.ScrollView
import com.dong.keyboardlayout.controller.KeyboardViewController
import kotlinx.android.synthetic.main.activity_keyboard.*

class KeyboardActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_keyboard)
        initView()
        initClickListener()
        scrollView.fullScroll(ScrollView.FOCUS_DOWN)
    }

    private fun initView() {
        keyboardLayout.keyBoardDriver.panelView = panel
        keyboardLayout.keyBoardDriver.kbViewController = object : KeyboardViewController {

            override fun scrollViewToBottom() {
                scrollView.fullScroll(ScrollView.FOCUS_DOWN)
            }

            override fun hideAllChildView() {
                emojiView.visibility = View.GONE
                moreFunctionView.visibility = View.GONE
            }
        }
    }

    private fun initClickListener() {
        switchIV.setOnClickListener {
            //当前显示表情
            if (panel.visibility == View.VISIBLE && emojiView.visibility == View.VISIBLE) {
                keyboardLayout.keyBoardDriver.switchCommon(showChildView = moreFunctionView, hideChildView = emojiView)
            }
            else {
                keyboardLayout.keyBoardDriver.switchCommon(editText = inputET, showChildView = moreFunctionView)
            }
        }

        switchEmoIV.setOnClickListener {
            //当前显示更多
            if (panel.visibility == View.VISIBLE && moreFunctionView.visibility == View.VISIBLE) {
                keyboardLayout.keyBoardDriver.switchCommon(showChildView = emojiView, hideChildView = moreFunctionView)
            }
            else{
                keyboardLayout.keyBoardDriver.switchCommon(editText = inputET, showChildView = emojiView)
            }
        }

        cancelIV.setOnClickListener {
            //当前显示表情
            if (panel.visibility == View.VISIBLE && emojiView.visibility == View.VISIBLE) {
                keyboardLayout.keyBoardDriver.switchCommon(hideChildView = emojiView)
            }
            //当前显示更多
            else if (panel.visibility == View.VISIBLE && moreFunctionView.visibility == View.VISIBLE) {
                keyboardLayout.keyBoardDriver.switchCommon(hideChildView = moreFunctionView)
            }
            //当前显示键盘
            else if (keyboardLayout.keyBoardDriver.keyboardShow == true) {
                keyboardLayout.keyBoardDriver.switchCommon(editText = inputET)
            }
        }
    }
}